//
//  ViewController.m
//  07-界面接传值
//
//  Created by 王道林 on 16/7/22.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()<SecondVCPassValue>
@property (nonatomic, strong) UILabel *lable;
@property (nonatomic, strong) UIButton *button;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    _lable = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];
    _lable.backgroundColor = [UIColor yellowColor];
    _lable.text = @"wang";
    [self.view addSubview:_lable];
    
    _button = [UIButton buttonWithType:UIButtonTypeSystem];
    _button.backgroundColor = [UIColor redColor];
    [self.view addSubview:_button];
    _button.frame = CGRectMake(200, 300, 100, 100);
    [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_button setTitle:@"点击进入" forState:UIControlStateNormal];
    
    
    
}


- (void)buttonAction:(UIButton *)button
{
    
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    secondVC.delegate = self;
    secondVC.text = _lable.text;
    [self.navigationController pushViewController:secondVC animated:YES];
    
    
    
    //界面通信
    // 1. 属行传值   一般常用于 从前往后传值
    
    //2.协议传值
    //第二页面给第一页面传值
    //给第二页面声明协议
    //1.决定要在second中声明协议
    //2.声明delegate @property id <XXX>delegate
    //3.在哪签订协议(只要可以拿到对象, 就可以签订协议)
    //4.XXX.delegate = self;
    //5.签订完协议 会报黄 为实现协议方法
    //6.触发协议 在第一页面 并加上判断
    
    
    //3.关于navigation中的控制器的释放
    //navigation中ViewController数组 数组对对象有引用计数 + 1
    // 当controller入栈时 则被加入数组中 引用计数加一
    //只要不出站 就不会释放
    //A push 到 B
    //B pop 回 A  B出栈 对应释放
    
    
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"%@", _texttitle);
}

// 协议方法

- (void)passValue:(NSString *)string
{
    _texttitle = string;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
